package com.spiro.normal.bio;

import com.spiro.common.BaseJavaClient;
import com.spiro.common.tutorial.Calculator;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;

import java.util.ArrayList;
import java.util.List;

public class BioClient extends BaseJavaClient {

    public BioClient(String host, int port) {
        super(host, port);
    }

    @Override
    public Calculator.Client connectAndGet() throws TException {
        transport = new TSocket(this.host, this.port);
        transport.open();

        TProtocol protocol = new TBinaryProtocol(transport);
        return new Calculator.Client(protocol);
    }

    public static List<BioClient> getInstances(int n, String host, int port) {
        List<BioClient> clients = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {
            clients.add(new BioClient(host, port));
        }

        return clients;
    }

}
